home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1996 October / MACPOWER-1996-10.ISO.7z / MACPOWER-1996-10.ISO / AMUG / Internet_31 / NetCacheResolver 0.9d6 / NetCacheResolver 0.9d6 ト / main.c next >
Text File  |  1996-05-12  |  3KB  |  152 lines

  1. // NetCache Resolver, 1995 (C) Mizutori Tetsuya
  2. // - main.c, October 8, 1995
  3. // This document is pretty printed in 10-point Geneva font.
  4.  
  5. #include "NCR_Basic.h"
  6. #include "NCR_Resolve.h"
  7. #include "NCR_AppleEvent.h"
  8. #include "NCR_Event.h"
  9. #include "NCR_FIle.h"
  10. #include "NCR_Qsort.h"
  11. #include "NCR_Error.h"
  12.  
  13. #ifdef DEBUG
  14. #include "NCR_Message.h"
  15. #endif /* DEBUG */
  16.  
  17. // definitions
  18.  
  19. // prototype
  20. /***** main *****/
  21. void main ( void );
  22.  
  23. /***** callback for MenuChoice *****/
  24. OSErr DoOpen ( WindowPtr window );
  25.  
  26. /***** callback for AppleEvent *****/
  27. OSErr DoOpenApplication ( void );
  28. OSErr DoQuitApplication ( void );
  29. OSErr DoPrintDocument ( void );
  30. OSErr DoOpenDocument ( FSSpec *theFSSpec, long index, long count );
  31.  
  32. /***** Do Operation *****/
  33. OSErr DoOperation ( FSSpec *theFSSpec );
  34.  
  35. /***** main *****/
  36. void main ( void )
  37. {
  38.     ToolboxInit();
  39.     SetupAppleEvent();
  40.     
  41. #ifdef DEBUG
  42.     NewMessage();
  43. //    MessageTest();
  44. //    DoOpen( (WindowPtr) nil );
  45. #endif /* DEBUG */
  46.  
  47.     EventLoop();
  48.     
  49.     ExitToShell();
  50. }
  51.  
  52.  
  53. /***** callback for MenuChoice *****/
  54. OSErr DoOpen ( WindowPtr window )
  55. {
  56.     FSSpec     theFSSpec;
  57.     short        numTypes = 1; //-1 for all types;
  58.     OSType    typeList[] = {'DBMC', 'TEXT', 0, 0};
  59.     OSErr    err;
  60.     
  61.     if ( ! GetFilename( &theFSSpec, numTypes, typeList ) ) return paramErr;
  62.     
  63.     err = DoOperation( &theFSSpec );
  64.     
  65.     return err;
  66. }
  67.  
  68.  
  69. /***** callback for AppleEvent *****/
  70. OSErr DoOpenApplication ( void )
  71. {
  72.     OSErr    err = noErr;
  73.     
  74.     SetupMenuBar();
  75.     
  76. //    err = DoOpen( (WindowPtr) nil );
  77.  
  78.     return err;
  79. }
  80.  
  81. OSErr DoQuitApplication ( void )
  82. {
  83.     // do nothing, here
  84.     
  85.     return noErr;
  86. }
  87.  
  88. OSErr DoPrintDocument ( void )
  89. {
  90.     // do nothing, here.
  91.     
  92.     return noErr;
  93. }
  94.  
  95. OSErr DoOpenDocument ( FSSpec *theFSSpec, long index, long count )
  96. {
  97.     OSErr    err;
  98.     
  99.     err = DoOperation( theFSSpec );
  100.     
  101.     return err;
  102. }
  103.  
  104. /***** Do Operation *****/
  105. OSErr DoOperation ( FSSpec *theFSSpec )
  106. {
  107.     FSSpec     theFSSpec2;
  108.     FInfo        theFInfo, theFInfo2;
  109.     Handle    theHndl = nil;
  110.     long        datasize;
  111.     Str63    cacheLog;                // read from 'STR#'
  112.     Str31    strFdType;
  113.     OSType    fdType = 'TEXT';            // read from 'STR#'
  114.     OSErr    err = noErr;
  115.  
  116.     GetIndString( cacheLog, STRID_CACHE, STRIX_CACHE );
  117.     GetIndString( strFdType, STRID_CACHE, STRIX_CACHETYPE );
  118.     BlockMove( &strFdType[1], &fdType, 4 );
  119.     
  120.     theHndl = NewHandleClear( 0 );        // create a Handle 'theHndl'
  121.     if ( (err=MemError()) != noErr ) { ErrorMessageMEM( err, true ); }
  122.  
  123.     err = GetRecordFromFile( theFSSpec, &theFInfo, theHndl, &datasize );
  124.     if ( err != noErr ) { ErrorMessageFS( err, false ); goto out; }
  125.  
  126.     theFInfo2 = theFInfo;
  127.     theFInfo2.fdType = fdType;
  128.  
  129.     theFSSpec2 = *theFSSpec;
  130.     BlockMove( cacheLog, theFSSpec2.name, cacheLog[0]+1);
  131.  
  132. #ifdef COMMENT
  133.     do {
  134.         long        fileID;
  135.         FSSpec     theFSSpec3;
  136.         
  137.         theFSSpec3 = theFSSpec2;
  138.         GenFilename( theFSSpec2.name, theFSSpec3.name );
  139.     } while ( QueryFile( &theFSSpec2, &fileID ) );
  140. #endif /* COMMENT */
  141.  
  142.     err = WriteFile( &theFSSpec2, &theFInfo2, theHndl, &datasize );
  143.     if ( err != noErr ) { ErrorMessageFS( err, false ); goto out; }
  144.  
  145.   out:
  146.     if ( theHndl != nil ) DisposeHandle( theHndl );    // dispose the Handle 'theHndl'
  147.  
  148.     return err;
  149. }
  150.  
  151. // end of program
  152.